﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace Elentok.Common
{
  /// <summary>
  /// This interface is required for various WPF stuff
  /// (WPF doesn't like arrays)
  /// <para>
  /// It's basically just a wrapper around an array
  /// </para>
  /// </summary>
  /// <typeparam name="T">The type of the array data</typeparam>
  public interface IArrayWrapper<T>
  {
    /// <summary>
    /// Returns the array within this wrapper.
    /// </summary>
    /// <returns>The inner array.</returns>
    T[] ToArray();
  }

  /// <summary>
  /// The default implementation of <see cref="IArrayWrapper&lt;T&gt;"/>
  /// </summary>
  /// <typeparam name="T">The type of the array items</typeparam>
  public class ArrayWrapper<T> : IArrayWrapper<T>
  {
    /// <summary>
    /// The inner array.
    /// </summary>
    private T[] data;

    /// <summary>
    /// Initializes a new instance of the <see cref="ArrayWrapper&lt;T&gt;"/> class
    /// </summary>
    /// <param name="data">The inner array.</param>
    public ArrayWrapper(T[] data)
    {
      this.data = data;
    }

    /// <summary>
    /// Returns the array within this wrapper.
    /// </summary>
    /// <returns>The inner array.</returns>
    public T[] ToArray()
    {
      return this.data;
    }
  }
}
